<?php
header("Content-Type: text/html; charset=utf-8"); 
require_once('sessionVal.php');

require("../config.inc.php");
require_once(COMM_PATH."BMS.php");
require_once (COMM_PATH . "upload.php");
require_once(COMM_PATH . "bookUtil.php");

$bms = new BMS();
$categoryList = $bms->getAllCategory();

if ($_SERVER['REQUEST_METHOD']=='POST'){
	$cateID = $_POST['F_ID'];
	$data['bookName'] =  $_POST['F_BOOK_NAME'];
	$data['author'] =  $_POST['F_AUTHOR'];
	$data['category'] = $_POST['F_CATEGORY'];
	$data['intro'] = $_POST['F_BOOK_RESERVE'];
	if($bms->updateData($bms->_BOOK,$cateID, $data)){
		echo "<script type=\"text/javascript\">alert(\"更新成功！\");window.location.href=\"booklist.php\";</script>";
		exit;
	}else{
		echo "<script type=\"text/javascript\">alert(\"更新失败！\");window.location.href=\"booklist.php\";</script>";
		exit();
	}
}else{
	$cateID = $_GET['F_ID'];
	$bookList = $bms->getInfo($cateID, $bms->_BOOK);
		if (!$bookList){
			echo '分类对象查询失败！';
			echo "<a href='category.php'>返回</a>";
			exit();
		}
		$book = $bookList[0];
}

?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
	<meta http-equiv="content-type" content="text/html; charset=UTF-8"/>
	<title>书籍管理</title>
	<link rel="stylesheet" href="../resources/css/admin/style.css" />
	<script src="../resources/js/jquerys/lib/jquery.js" type="text/javascript"></script>
	<script src="../resources/js/jquerys/lib/jquery.cookie.js" type="text/javascript"></script>
	<script type="text/javascript" src="../resources/js/util.js"></script>
	<script type="text/javascript">
	function check(){
		var Mainform = document.form1;
		if(Mainform.F_BOOK_NAME.value==""){
			alert("书籍名称不能为空！");
			return false;
		}
		if(Mainform.F_BOOK_NAME.value.len()>200){
			alert("书籍名称不能超过100个字！");
			return false;
		}
		
		if(Mainform.F_AUTHOR.value==""){
			alert("作者不能为空！");
			return false;
		}
		if(Mainform.F_AUTHOR.value.len()>100){
			alert("作者不能超过50个字！");
			return false;
		}

		if(Mainform.F_CATEGORY.value==""){
			alert("类别不能为空！");
			return false;
		}
		
		return true;
		
	}
	</script>
	</head>
	<body>
	<div id="wrap">
		<div id="adminmenuback"></div>
		<div id="menu">
			<h3 class="menutop">控制台</h3>
			<?php require('menus.php');?>
		</div>
		<div id="main-content">
			<?php require('top.php');?>
          	  
          	<div id="wpcontent">
          		
          	    <h2>修改书籍</h2>
          	    <div id="mainform">
          	    	<form action="" name="form1"  method="post" enctype="multipart/form-data"  >
          	    	<input type="hidden" name="F_ID" value="<?php echo $cateID?>" />
          	    		<table width="78%" border="1" align="center" cellspacing="0" id="table_1" class="table_1">
					 		<thead class="tb_side">
					 		<tr >
					 			<td colspan="2">&nbsp;</td>
					 		</tr>
					 		</thead>
					 		<tbody class="tb_body">
					 		<tr>
					 			<td width="25%" align="center">书籍名称<font color="red">*</font></td>
					 			<td width="75%" colspan="3"><input type="text" name="F_BOOK_NAME"  id="f-book" style="width:300px;" value="<?php echo $book['bookName']?>" /></td>
					 		</tr>
					 		<tr>
					 			<td align="center">作者<font color="red">*</font></td>
					 			<td><input type="text" name="F_AUTHOR"  id="f-author" value="<?php echo $book['author']?>"  /></td>
					 			<td  align="center">类别<font color="red">*</font></td>
					 			<td >
					 				<select name="F_CATEGORY">
					 					<option value="" >--请选择--</option>
					 					<?php
					 					if ($categoryList){
						 					 foreach ($categoryList as $key => $value) {
						 					 	if ($book['category']==$value[BID]){
						 					 		echo "<option value=\"$value[BID]\" selected=\"selected\">$value[cate_name]</option>";
						 					 	}else{
						 					 		echo "<option value=\"$value[BID]\">$value[cate_name]</option>";
						 					 	}
						 					 }
					 					}
					 					?>
					 				</select>
					 			</td>
					 		</tr>
					 		<tr>
					 			<td align="center">书籍简介</td>
					 			<td colspan="3">
						 			<textarea rows="2" cols="50" name="F_BOOK_RESERVE"><?php echo $book['intro']?></textarea>
					 			</td>
					 		</tr>
					 		
					 		</tbody>
					 		<tfoot class="tb_side">
					 		<tr>
					 			<td colspan="4" align="center">
					 				<input type="submit" name="AddBook" value="保  存" class="button"/>&nbsp;&nbsp;&nbsp;&nbsp;
					 				<input type="reset" name="resetbtn" value="重  置" class="button"/>&nbsp;&nbsp;&nbsp;&nbsp;
					 				<input type="button" name="backbtn" value="返  回" class="button" onclick="javascript:window.location.href='booklist.php'"/>
					 			</td>
					 		</tr>
					 		</tfoot>
					 	</table>
          	    		
          	    	</form>
          	    </div>
          	</div>
          	  
		</div>
 	</div>
</body>
</html>

